<?php

namespace App\Containers\AppSection\Log\UI\API\Transformers;

use App\Containers\AppSection\Log\Models\Log;
use App\Containers\AppSection\Profile\UI\API\Transformers\ProfileTransformer;
use App\Containers\AppSection\Type\UI\API\Transformers\TypeTransformer;
use App\Ship\Parents\Transformers\Transformer;
use League\Fractal\Resource\Item;

class LogTransformer extends Transformer
{

    /**
     * @var  array
     */
    protected array $availableIncludes = [
        'profile',
        'type'
    ];

    public function transform(Log $t): array
    {
        return [
            'object' => $t->getResourceKey(),
            'include' => $this->getAvailableIncludes(),
            'id' => $t->getHashedKey(),
            'log' => $t->log,
            'type_key' => $t->type_key,
            'relation_id' => $t->relation_id,
            'created_at' => $this->dateTimeFormatter($t->created_at),
            'updated_at' => $this->dateTimeFormatter($t->updated_at),
            'readable_created_at' => $t->created_at->diffForHumans(),
            'readable_updated_at' => $t->updated_at->diffForHumans()
        ];
    }

    public function includeProfile(Log $t): Item
    {
        return $this->item($t->profile, new ProfileTransformer);
    }

    public function includeType(Log $t): ?Item
    {
        return $this->nullableItem($t->type, new TypeTransformer);
    }
}
